<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<!-- 用来将jsx语法转化为js语法 -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
<script type="text/babel">
    class App extends React.Component {
        state = {
            num: 0,
        }
        render() {
            let { num } = this.state;
            return (
                <div>
                    <h1>插槽的基本使用</h1>
                    <button onClick={() => {
                        this.setState((state) => {
                            return {
                                num: state.num + 1
                            }
                        })
                    }}>
                        ++</button>
                    <Child>
                        {num}
                    </Child>
                    <ChlidTwo>
                        <div>头部</div>
                        <div>内容</div>
                        <div>底部</div>
                        哈哈哈
                    </ChlidTwo>
                </div>
            )
        }
    }
    class Child extends React.Component {
        state = {

        }
        render() {
            console.log(this);
            return (
                <div>
                    {
                        // 组件内部所携带的内容就是插槽
                        // this.props.children 获取组件插槽内容
                    }
                    <h2>child组件---{this.props.children}</h2>
                </div>
            )
        }
    }
    class ChlidTwo extends React.Component {
        state = {

        }
        render() {
            console.log(this);
            // 若插槽内容有多个虚拟节点 那么 this.props.children就是一个数组
            // 全部显示 则可以直接使用 this.props.children 单个展示 则可以根据索引展示想要渲染的插槽内容
            return (
                <div>
                    {
                        this.props.children[0]
                    }
                    <h1>childTwo组件</h1>
                    {
                        this.props.children[1]
                    }{
                        this.props.children[2]
                    }
                </div>
            )
        }
    }
    ReactDOM.render(<App />, document.getElementById('root'));
</script>

</html>